package ma.ensao.evalmetrics.util.javaProjects;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Method;

import com.thoughtworks.qdox.JavaDocBuilder;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.JavaPackage;
import com.thoughtworks.qdox.model.JavaSource;
/*
*Classe pour extraire les classes java 
*/
public class JavaClasses {
	JavaMethod[][] classesMethodsNames;
	JavaField[][] classesAttributesNames;
	JavaClass[] classesNames;
	JavaPackage classesPackage;
	File sourceFile;
	public JavaClasses(File file){
		setSourceFile(file);
	}
	public JavaField[][] getClassesAttributesNames() {
		return classesAttributesNames;
	}
	public void setClassesAttributesNames(JavaField[][] classesAttributesNames) {
		this.classesAttributesNames = classesAttributesNames;
	}
	//Definie les noms des classes
	public  void ClassesNames() {
		JavaDocBuilder builder = new JavaDocBuilder();

		try {
			builder.addSource(sourceFile);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 JavaSource src = builder.getSources()[0];
		 JavaClass[] javaClass = src.getClasses();
		 this.setClassesNames(javaClass);
	}
	//Definie les noms des packeges
	public void packagesNames(){
		ClassesNames();
		setClassesPackage(classesNames[0].getPackage());
	}
	public JavaPackage getClassesPackage() {
		return classesPackage;
	}
	public void setClassesPackage(JavaPackage classesPackage) {
		this.classesPackage = classesPackage;
	}
	public JavaMethod[][] getClassesMethodsNames() {
		return classesMethodsNames;
	}
	public JavaClass[] getClassesNames() {
		return classesNames;
	}
	public File getSourceFile() {
		return sourceFile;
	}
	//Definie les noms des methodes
	public void MethodsNames(JavaClass[] javaClass) {
		JavaMethod[][] javaMethod= new JavaMethod[javaClass.length][];
	    
	    for (int i = 0; i < javaClass.length; i++) {
	    	javaMethod[i]= javaClass[i].getMethods();
		}
	   
		this.setClassesMethodsNames(javaMethod);
		
	}
	//Definie les noms des attrubes
	public void attributesNames(JavaClass[] javaClass) {
		JavaField[][] javaAttributes= new JavaField[javaClass.length][];
	    
	    for (int i = 0; i < javaClass.length; i++) {
	    	javaAttributes[i]= javaClass[i].getFields();
		}
	   
		this.setClassesAttributesNames(javaAttributes);
		
	}
	public void setClassesMethodsNames(JavaMethod[][] classesMethodsNames) {
		this.classesMethodsNames = classesMethodsNames;
	}
	public void setClassesNames(JavaClass[] classesNames) {
		this.classesNames = classesNames;
	}
	public void setSourceFile(File file) {
		this.sourceFile = file;
	}
}
